﻿using Bear.Library;
using Bear.Library.WinApi;
using Bear.Library.WinForm;

using Bear.Models;
using PeopleSimulator;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Bear.MapleStory
{
    public partial class OptionForm : Form
    {
        public BindingList<Map> _Maps = null;
        public BindingList<Script> _Scripts = null;
        public BindingList<Player> _Players = null;

        #region 初始化配置文件

        private void InitAppConfig()
        {
            this.Config = AppConfig.Load();


            this.tbGamePath.Text = Config.GamePath;
            this.tbGameTitle.Text = Config.GameTitle;
            this.numChannel.Value = Config.Channel;


            tbHP.Text = Convert.ToString(this.Config.LifeRate);
            tbMP.Text = Convert.ToString(this.Config.MagicRate);
            tbHPCount.Text = Convert.ToString(this.Config.LifePotion);
            tbMPCount.Text = Convert.ToString(this.Config.MagicPotion);
            tbLifeCycleTime.Text = Convert.ToString(this.Config.LifeCycleTime);
            tbMagicCycleTime.Text = Convert.ToString(this.Config.MagicCycleTime);
            tbKeyRate.Text = Convert.ToString(this.Config.KeyRate);
            tbPickCycleTime.Text = Convert.ToString(this.Config.PickCycleTime);
            tbMoveDistance.Text = Convert.ToString(this.Config.MoveDistance);
            tbStepWaitTime.Text = Convert.ToString(this.Config.StepWaitTime);
            cbAlarmPitch.SelectedItem = this.Config.AlarmPitch;
            cbVerificationOffline.Checked = this.Config.IsVerificationOffline;
            tbAlarmInterval.Text = Convert.ToString(this.Config.AlarmInterval);

        }

        #endregion

        #region 注册事件

        private void RegisterEvent()
        {
            butPlayerCreate.Click += (sender, e) =>
            {
                #region 创建新人物
                string name = tbAccountName.Text.Trim();
                if (string.IsNullOrEmpty(name))
                {
                    LoliMessageBox.Show(this, "请填写账户名称！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    tbAccountName.Focus();
                    return;
                }

                string password = tbAccountPassword.Text.Trim();
                if (string.IsNullOrEmpty(password))
                {
                    LoliMessageBox.Show(this, "请填写账户密码！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    tbAccountPassword.Focus();
                    return;
                }


                string securityCode = tbSecurityCode.Text.Trim();
                if (string.IsNullOrEmpty(securityCode))
                {
                    LoliMessageBox.Show(this, "请填写安全码！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    tbSecurityCode.Focus();
                    return;
                }

                int role = -1;
                int.TryParse(numRole.Text, out role);
                if (role < 0)
                {
                    LoliMessageBox.Show(this, "请填写角色号！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    numRole.Focus();
                    return;
                }

                Player player = this._Players.FirstOrDefault(t => t.AccountName == name && t.Role == role);
                if (player != null)
                {
                    DialogResult result = LoliMessageBox.Show(this,
                        string.Format("角色 {0} 已经存在，是否覆盖？", name), "问题", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == System.Windows.Forms.DialogResult.Yes)
                    {
                        player.AccountName = name;
                        player.Role = role;
                        player.Password = password;
                        player.SecurityCode = securityCode;
                    }
                    return;
                }

                this._Players.Add(new Player()
                {
                    AccountName = name,
                    Role = role,
                    Password = password,
                    SecurityCode = securityCode,
                });

                #endregion
            };          

            lbPlayers.SelectedIndexChanged += (sender, e) =>
            {
                #region 人物列表选择
                Player player = lbPlayers.SelectedItem as Player;
                tbAccountName.Text = player.AccountName;
                tbAccountPassword.Text = player.Password;
                tbSecurityCode.Text = player.SecurityCode;
                numRole.Text = Convert.ToString(player.Role);


                if (player == null)
                {
                    this.lbSkills.DataSource = null;
                }
                else
                {
                    this.lbSkills.DisplayMember = "DisplayString";
                    this.lbSkills.DataSource = new BindingSource() { DataSource = player.Skills };
                }
                #endregion
            };

            butPlayerRemove.Click += (sender, e) =>
            {
                #region 删除人物
                if (this.lbPlayers.SelectedItem != null)
                {
                    DialogResult result = LoliMessageBox.Show(this, "确定要删除人物吗？", "信息",
                        MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

                    if (result == System.Windows.Forms.DialogResult.OK)
                    {
                        this._Players.Remove(this.lbPlayers.SelectedItem as Player);
                    }
                }
                #endregion
            };

            butSkillCreate.Click += (sender, e) =>
            {
                #region 技能创建

                Player player = lbPlayers.SelectedItem as Player;

                if (player == null)
                {
                    LoliMessageBox.Show(this, "请先设置人物！", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                //获取key
                KeyCodes keyCode = (KeyCodes)tbSkillKey.KeyCode;
                if (keyCode == KeyCodes.None)
                {
                    LoliMessageBox.Show(this, "请指定Buff按键！", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.tbSkillKey.Focus();
                    return;
                }


                int duration = int.Parse(tbSkillDuration.Text);
                if (duration <= 0)
                {
                    LoliMessageBox.Show(this, "请指定技能持续时间！", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.tbSkillDuration.Focus();
                    return;
                }


                int actionTime = int.Parse(tbSkillActionTime.Text);
                if (actionTime <= 0)
                {
                    LoliMessageBox.Show(this, "请指定技能动作时间！", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.tbSkillActionTime.Focus();
                    return;
                }

                string id = tbSkillID.Text;
                if (string.IsNullOrWhiteSpace(id))
                {
                    LoliMessageBox.Show(this, "请指定技能ID！", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.tbSkillID.Focus();
                    return;
                }



                if (player.Skills == null)
                {
                    player.Skills = new List<Skill>();
                };


                Skill skill = player.Skills.FirstOrDefault(t => t.ID == id);

                if (skill != null)
                {
                    DialogResult result = LoliMessageBox.Show(this,
                        string.Format("技能 {0} 已经存在，是否覆盖？", id), "问题", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == System.Windows.Forms.DialogResult.Yes)
                    {
                        skill.ActionTime = actionTime;
                        skill.Duration = duration;
                        skill.KeyCode = keyCode;
                    }
                    return;
                }


                player.Skills.Add(new Skill()
                {
                    ID = id,
                    ActionTime = actionTime,
                    Duration = duration,
                    KeyCode = keyCode,
                });


                if (this.lbSkills.DataSource == null)
                {
                    this.lbSkills.DisplayMember = "DisplayString";
                    this.lbSkills.DataSource = new BindingSource() { DataSource = player.Skills };
                }
                else
                {
                    (this.lbSkills.DataSource as BindingSource).ResetBindings(false);
                }

                this.tbSkillKey.Focus();
                #endregion
            };

            butSkillRemove.Click += (sender, e) =>
            {
                #region 技能删除
                Player player = lbPlayers.SelectedItem as Player;
                if (player != null)
                {
                    Skill skill = this.lbSkills.SelectedItem as Skill;
                    if (skill != null)
                    {
                        player.Skills.Remove(this.lbSkills.SelectedItem as Skill);
                        (this.lbSkills.DataSource as BindingSource).ResetBindings(false);
                    }
                }

                #endregion
            };

            lbSkills.SelectedIndexChanged += (sender, e) =>
            {
                #region 技能列表选择
                Skill skill = lbSkills.SelectedItem as Skill;
                tbSkillActionTime.Text = Convert.ToString(skill.ActionTime);
                tbSkillDuration.Text = Convert.ToString(skill.Duration);
                tbSkillKey.KeyCode = (Keys)skill.KeyCode;
                tbSkillID.Text = Convert.ToString(skill.ID);
                #endregion
            };

            btnSkillIDCreate.Click += (sender, e) =>
            {
                #region 创建技能ID
                tbSkillID.Text = Convert.ToString(DateTime.Now.Ticks);
                #endregion
            };

            butSave.Click += (sender, e) =>
            {
                #region 保存数据
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                DataCenter dc = DataCenter.Load();
                //获取buff列表            

                this.Config.LifeRate = Convert.ToInt32(tbHP.Text);
                this.Config.MagicRate = Convert.ToInt32(tbMP.Text);
                this.Config.LifePotion = Convert.ToInt32(tbHPCount.Text);
                this.Config.MagicPotion = Convert.ToInt32(tbMPCount.Text);
                this.Config.LifeCycleTime = Convert.ToInt32(tbLifeCycleTime.Text);
                this.Config.MagicCycleTime = Convert.ToInt32(tbMagicCycleTime.Text);
                this.Config.KeyRate = Convert.ToInt32(tbKeyRate.Text);
                this.Config.MoveDistance = Convert.ToInt32(tbMoveDistance.Text);
                this.Config.PickCycleTime = Convert.ToInt32(tbPickCycleTime.Text);
                this.Config.StepWaitTime = Convert.ToInt32(tbStepWaitTime.Text);
                this.Config.AlarmPitch = Convert.ToInt32(cbAlarmPitch.SelectedItem);
                this.Config.IsVerificationOffline = cbVerificationOffline.Checked;
                this.Config.AlarmInterval = Convert.ToInt32(tbAlarmInterval.Text);
                this.Config.GamePath = this.tbGamePath.Text;
                this.Config.GameTitle = this.tbGameTitle.Text;
                this.Config.Channel = Convert.ToInt32(this.numChannel.Value);

                //获取地图列表
                dc.Maps.Clear();
                foreach (var item in this._Maps)
                {
                    dc.Maps.Add(item);
                }

                //获取人物列表
                dc.Players.Clear();
                foreach (var item in this._Players)
                {
                    dc.Players.Add(item);
                }
                //保存
                this.Config.Save();
                dc.Maps.Save();
                dc.Players.Save();
                this.Close();
                #endregion
            };

            butClose.Click += (sender, e) =>
            {
                #region 关闭窗口
                this.Close();
                #endregion
            };



        }

        #endregion

        private AppConfig Config { get; set; }

        public OptionForm()
        {
            DataCenter dc = DataCenter.Load();
            InitializeComponent();

            this.InitAppConfig();
            this.RegisterEvent();

            tbSkillActionTime.Text = "500";
            tbSkillDuration.Text = "240";
            tbStepDuration.Text = "1000";


            this.lbSkills.DisplayMember = "DisplayString";
            this.lbSteps.DisplayMember = "DisplayString";

            this._Maps = new BindingList<Map>();
            this.lbMaps.DataSource = _Maps;
            this.lbMaps.DisplayMember = "DisplayString";

            this._Scripts = new BindingList<Script>();
            this.lbScript.DataSource = _Scripts;
            this.lbScript.DisplayMember = "Name";


            this._Players = new BindingList<Player>();
            this.lbPlayers.DataSource = _Players;
            this.lbPlayers.DisplayMember = "DisplayString";


            this.cbStepConnectionPointMode.SelectedIndex = 0;

            foreach (var item in dc.Maps)
            {
                this._Maps.Add(item);
            }


            foreach (var item in dc.Players)
            {
                this._Players.Add(item);
            }

        }

        protected override void OnClosing(CancelEventArgs e)
        {
            this.Hide();
            this.InitMapInput();
            this.InitStepInput();
        }


           #region 地图设置

        private void butMapCreate_Click(object sender, EventArgs e)
        {
            string name = tbMapName.Text.Trim();

            if (string.IsNullOrWhiteSpace(name))
            {
                LoliMessageBox.Show(this, "请填写地图名称！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                tbMapName.Focus();
                return;
            }


            //获取size
            string size = tbMapSize.Text;

            string[] sizes = size.Split('*', '，', ',');
            if (sizes.Length != 2)
            {
                LoliMessageBox.Show(this, "请正确填写地图大小！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                tbMapSize.Focus();
                return;
            }


            

            Map map = null;

            if (butMapCreate.Text == "修改")
            {
                map = this._Maps.FirstOrDefault(t => t.Name == name);
                if (map == null)
                {
                    DialogResult result = LoliMessageBox.Show(this,
                        string.Format("地图 {0} 不存在，是否创建？", name), "问题", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == System.Windows.Forms.DialogResult.No)
                    {
                        return;
                    }
                }

            }
            else
            {
                map = this._Maps.FirstOrDefault(t => t.Name == name);
                if (map != null)
                {
                    DialogResult result = LoliMessageBox.Show(this,
                        string.Format("地图 {0} 已经存在，是否覆盖？", name), "问题", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == System.Windows.Forms.DialogResult.No)
                    {
                        return;
                    }
                }
            }

            if (map == null)
            {
                map = new Map()
                {
                    Name = name,
                    Left = MapleStory._LEFT,
                    Top = MapleStory._TOP,
                    Width = int.Parse(sizes[0]),
                    Height = int.Parse(sizes[1]),                  
                };
                this._Maps.Add(map);
            }
            else
            {
                map.Left = MapleStory._LEFT;
                map.Top = MapleStory._TOP;
                map.Width = int.Parse(sizes[0]);
                map.Height = int.Parse(sizes[1]);              
            }

            this.InitMapInput();
        }

        private void butMapRemove_Click(object sender, EventArgs e)
        {
            if (butMapRemove.Text == "取消")
            {
                this.InitMapInput();
            }
            else
            {
                if (this.lbMaps.SelectedItem != null)
                {
                    DialogResult result = LoliMessageBox.Show(this, "确定要删除地图吗？", "信息",
                        MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

                    if (result == System.Windows.Forms.DialogResult.OK)
                    {
                        this._Maps.Remove(this.lbMaps.SelectedItem as Map);
                    }
                }
            }
        }

        private void lbMaps_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (butMapRemove.Text == "取消")
            {
                this.InitMapInput();
            }
            Map map = lbMaps.SelectedItem as Map;
            if (map == null)
            {
                this.lbSteps.DataSource = null;
            }
            else
            {
                this.lbSkills.DisplayMember = "DisplayString";
                this.lbSteps.DataSource = new BindingSource() { DataSource = map.Steps };
            }
            this.InitStepInput();
        }

        private void lbMaps_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                int index = lbMaps.IndexFromPoint(e.X, e.Y);
                if (index >= 0)
                {
                    Map map = lbMaps.Items[index] as Map;
                    lbMaps.SelectedIndex = index;

                    tbMapSize.Text = map.Width + "*" + map.Height;
                    tbMapName.Text = map.Name;
              

                    butMapRemove.Text = "取消";
                    butMapCreate.Text = "修改";
                }
            }
        }

        private void InitMapInput()
        {
            //清空添加数据         
            this.tbMapName.Text = string.Empty;
            this.tbMapSize.Text = string.Empty;
            
            butMapCreate.Text = "添加";
            butMapRemove.Text = "移除";
        }

        private void butStepCreate_Click(object sender, EventArgs e)
        {
            Map map = lbMaps.SelectedItem as Map;
            if (map == null)
            {
                LoliMessageBox.Show(this, "请先选择地图！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }


            string left = tbStepLeft.Text.Trim();
            string[] lefts = left.Split('*', '，', ',');
            if (lefts.Length != 2)
            {
                LoliMessageBox.Show(this, "请正确填写左侧坐标！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                tbStepLeft.Focus();
                return;
            }

            string right = tbStepRight.Text.Trim();

            string[] rights = right.Split('*', '，', ',');
            if (rights.Length != 2)
            {
                LoliMessageBox.Show(this, "请正确填写右侧坐标！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                tbStepRight.Focus();
                return;
            }

            string connectionPoint = tbStepConnectionPoint.Text.Trim();

            string[] connectionPoints = connectionPoint.Split('*', '，', ',');
            if (connectionPoints.Length != 2)
            {
                LoliMessageBox.Show(this, "请正确填写连接点坐标！", "错误",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                tbStepConnectionPoint.Focus();
                return;
            }

            string duration = tbStepDuration.Text.Trim();
            if (string.IsNullOrEmpty(duration))
            {
                LoliMessageBox.Show(this, "请正确填写动作时间！", "错误",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                tbStepDuration.Focus();
                return;
            }

            if (map.Steps == null)
            {
                map.Steps = new List<Step>();
            }

            int id = map.Steps.Count;
            if (!string.IsNullOrEmpty(tbStepID.Text))
            {
                id = int.Parse(tbStepID.Text);
            }

            int leftX = int.Parse(lefts[0]);
            int leftY = int.Parse(lefts[1]);
            int rightX = int.Parse(rights[0]);
            int rightY = int.Parse(rights[1]);
            int connX = int.Parse(connectionPoints[0]);
            int connY = int.Parse(connectionPoints[1]);
            //验证
            if (leftX >= rightX)
            {
                LoliMessageBox.Show(this, "左侧X坐标必须小于右侧X坐标！", "错误",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (leftY != rightY)
            {
                LoliMessageBox.Show(this, "左右两侧Y坐标不同！", "错误",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }


            string modeString = cbStepConnectionPointMode.SelectedItem.ToString();
            Directions mode = Directions.Down;
            switch (modeString)
            {
                case "上":
                    mode = Directions.Up;
                    break;
                case "下":
                    mode = Directions.Down;
                    break;
                case "左":
                    mode = Directions.Left;
                    break;
                case "右":
                    mode = Directions.Right;
                    break;
            }

            Point pleft = new Point(leftX, leftY);
            Point pRight = new Point(rightX, rightY);
            Point pConnectionPoint = new Point(connX, connY);
            int iDuration = int.Parse(duration);
            bool isJump = cbStepJump.Checked;


            if (butStepCreate.Text == "修改")
            {
                Step step = map.Steps.FirstOrDefault(t => t.ID == id);
                step.Left = pleft;
                step.Right = pRight;
                step.ConnectionPoint = pConnectionPoint;
                step.ConnectionPointMode = mode;
                step.Duration = iDuration;
                step.IsJump = isJump;
            }
            else
            {
                Step step = new Step()
                {
                    ID = id,
                    Left = pleft,
                    Right = pRight,
                    ConnectionPoint = pConnectionPoint,
                    ConnectionPointMode = mode,
                    Duration = iDuration,
                    IsJump = isJump
                };
                map.Steps.Add(step);
            }

            if (this.lbSteps.DataSource == null)
            {
                this.lbSteps.DisplayMember = "DisplayString";
                this.lbSteps.DataSource = new BindingSource() { DataSource = map.Steps };
            }
            else
            {
                (this.lbSteps.DataSource as BindingSource).ResetBindings(false);
            }

            this.InitStepInput();

        }

        private void butStepRemove_Click(object sender, EventArgs e)
        {
            if (butStepRemove.Text == "取消")
            {
                this.InitStepInput();
            }
            else if (butStepRemove.Text == "移除")
            {
                Map map = lbMaps.SelectedItem as Map;
                if (map != null)
                {
                    Step step = this.lbSteps.SelectedItem as Step;
                    if (step != null)
                    {
                        map.Steps.Remove(this.lbSteps.SelectedItem as Step);
                        (this.lbSteps.DataSource as BindingSource).ResetBindings(false);
                    }
                }
            }
        }

        private void lbSteps_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                int index = lbSteps.IndexFromPoint(e.X, e.Y);

                if (index >= 0)
                {
                    Step step = lbSteps.Items[index] as Step;
                    lbSteps.SelectedIndex = index;

                    cbStepConnectionPointMode.SelectedItem = step.ConnectionPointMode;
                    cbStepJump.Checked = step.IsJump;
                    tbStepRight.Text = step.Right.X + "*" + step.Right.Y;
                    tbStepLeft.Text = step.Left.X + "*" + step.Left.Y;
                    tbStepDuration.Text = step.Duration.ToString();
                    tbStepConnectionPoint.Text = step.ConnectionPoint.X + "*" + step.ConnectionPoint.Y;
                    tbStepID.Text = Convert.ToString(step.ID);

                    butStepCreate.Text = "修改";
                    butStepRemove.Text = "取消";
                }
            }
        }

        private void lbSteps_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (butStepRemove.Text == "取消")
            {
                this.InitStepInput();
            }
        }

        private void InitStepInput()
        {
            tbStepID.Text = string.Empty;
            tbStepDuration.Text = "1000";
            tbStepLeft.Text = string.Empty;
            tbStepRight.Text = string.Empty;
            tbStepConnectionPoint.Text = string.Empty;
            butStepCreate.Text = "添加";
            butStepRemove.Text = "移除";
        }

        private void butGetPoint_Click(object sender, EventArgs e)
        {
            IntPtr handle = MapleStory.FindWindow();

            Map map = lbMaps.SelectedItem as Map;
            if (map == null)
            {
                LoliMessageBox.Show(this, "请先选择地图！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (handle == IntPtr.Zero)
            {
                LoliMessageBox.Show(this, "请先开启游戏！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            WinApiHelper.ShowWindow(handle, 1);
            WinApiHelper.SetForegroundWindow(handle);
            Thread.Sleep(500);

            Point point = PlayerAction.FindPlayerLocation(map, DataCenter.Load().Players.MapPoint);
            this.labLocation.Tag = point;
            this.labLocation.Text = point.X + "*" + point.Y;
        }

        private void labLocation_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            this.msPoint.Show(labLocation, 0, labLocation.Height);
        }

        private void miPointToLeft_Click(object sender, EventArgs e)
        {
            if (this.labLocation.Tag != null)
            {
                Point point = (Point)this.labLocation.Tag;


                ToolStripMenuItem source = sender as ToolStripMenuItem;

                TextBox tb = null;
                switch (source.Name)
                {
                    case "miPointToLeft":
                        tb = tbStepLeft;
                        break;
                    case "miPointToConnection":
                        tb = tbStepConnectionPoint;
                        break;
                    case "miPointToRight":
                        tb = tbStepRight;
                        break;
                }
                tb.Text = point.X + "*" + point.Y;
            }
        }


        #endregion

        #region 基本设置

        private void butSpeak_Click(object sender, EventArgs e)
        {
            DataCenter dc = DataCenter.Load();
            dc.Action.Speak(Convert.ToInt32(cbAlarmPitch.SelectedItem), 200);
            Thread.Sleep(100);
            dc.Action.Speak(Convert.ToInt32(cbAlarmPitch.SelectedItem), 200);
            Thread.Sleep(100);
            dc.Action.Speak(Convert.ToInt32(cbAlarmPitch.SelectedItem), 200);
            Thread.Sleep(100);
            dc.Action.Speak(Convert.ToInt32(cbAlarmPitch.SelectedItem), 30);
            Thread.Sleep(100);
            dc.Action.Speak(Convert.ToInt32(cbAlarmPitch.SelectedItem), 30);
            Thread.Sleep(100);
        }

        #endregion

       



    }
}
